class ScorePanel {
  // 分数
  score = 0;
  // 等级
  level = 1;
  // 最大等级
  maxLevel: number;
  // 多少分升一级
  upScore: number;

  scoreSpan: HTMLElement;
  levelSpan: HTMLElement;
  constructor(maxLevel: number, upScore: number) {
    this.scoreSpan = document.getElementById('score')!;
    this.levelSpan = document.getElementById('level')!;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }

  addScore() {
    this.scoreSpan.innerHTML = (++this.score).toString();
    if (this.score % this.upScore === 0) {
      this.upLevel();
    }
  }

  upLevel() {
    if (this.level < this.maxLevel) {
      this.levelSpan.innerHTML = (++this.level).toString();
    }
  }
}

export default ScorePanel;
